
package com.jf.cloud.service.sysmanager.remote;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.jf.cloud.service.sysmanager.common.base.AjaxPageData;
import com.jf.cloud.service.sysmanager.dao.ICardBatchService;
import com.jf.cloud.service.sysmanager.entity.SysStaff;
import com.jf.cloud.service.sysmanager.handler.TokenHandler;
import com.jf.cloud.service.sysmanager.support.entity.Result;
import com.jf.cloud.service.sysmanager.support.web.BaseController;
import com.jf.cloud.service.sysmanager.vo.CardOptUserVO;

/**
 * 员工控制器
 *
 * @author 代码机1.0 创建时间：2018-03-31
 */
@Controller
@RequestMapping("/cardBatch")
public class CardBatchController extends BaseController {

    /**
     * 日志
     */
    private static Log log = LogFactory.getLog(CardBatchController.class);

    @Autowired
    private TokenHandler tokenHandler;

    @Autowired
    private ICardBatchService cardBatchService;


    /**
     * 获取批次列表数据
     */
    @ResponseBody
    @RequestMapping("/list")
    public Result submit(String token, HttpServletRequest request) {
        AjaxPageData<CardOptUserVO> dataPage = new AjaxPageData();
        try {
            SysStaff sysStaff = tokenHandler.getSysStaffInfoByToken(token);
            if (sysStaff == null) {
                return new Result.ResultBuiler().failed("登录失效");
            }
            List list = cardBatchService.findAll();
            if (list != null) {
                return new Result.ResultBuiler().success(list);
            } else {
                return new Result.ResultBuiler().failed("获取项目统计失败");
            }
        } catch (Exception e) {
            log.error("获取项目统计出错！", e);
            return new Result.ResultBuiler().error();
        }
    }

    /**
     * 获取用户列表数据
     */
    @ResponseBody
    @RequestMapping("/list/new")
    public List<Map<String,Object>> listNew(String token, HttpServletRequest request) {
        try {
            SysStaff sysStaff = tokenHandler.getSysStaffInfoByToken(token);
            if (sysStaff == null) {
                return null;
            }
            List<Map<String,Object>> list = cardBatchService.findNew();
            if (list != null) {
                return list;
            } else {
                return null;
            }
        } catch (Exception e) {
            log.error("获取项目统计出错！", e);
            return null;
        }
    }

}
